package com.lagou.rocketmq.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
public class UrlController {

    @GetMapping("/seckill/url")
    public Map<String, Object> getUrl(@RequestParam Integer productId) {
        String url = "";

        if(LocalDateTime.now().compareTo(LocalDateTime.parse("2020-08-10T05:00:00")) >= 0) {
            url = "/order/" + productId;
        }

        Map<String, Object> result = new HashMap<>();
        result.put("url", url);
        return result;
    }
}
